<template>
  <departmentBase>
    <template v-slot:main-left>
      <SearchTrees
        ref="SearchTrees"
        :treeData="treeData"
        :defaultProps="defaultProps"
        :lazy="lazy"
        @getlazyLoad="lazyLoad"
        @deleteHandle="deleteHandle"
        @handleNodeClickTree="handleNodeClickTree"
      />
    </template>
    <template v-slot:search-info>
      <div class="main-search">
        <el-row :gutter="15">
          <el-col :span="8">
            <treeselect
              v-model="filterText"
              :options="OrgOptions"
              :load-options="loadOptions"
              :normalizer="normalizer"
              clearable
              placeholder="请选择机构"
              @select="chooseAnOrgan"
              @input="inputAnOrgan"
            >
              <label
                slot="option-label"
                slot-scope="{ node, labelClassName }"
                :class="labelClassName"
                :title="node.label"
              >
                {{ node.label }}
              </label>
            </treeselect>
          </el-col>
          <el-col :span="16">
            <el-form
              :model="listQuery"
              ref="commonForm"
              inline
              label-width="auto"
              class="demo-ruleForm"
            >
              <el-col :span="6">
                <el-form-item prop="label" class="item">
                  <el-input
                    clearable
                    placeholder="科室名称、科室编码"
                    v-model.trim="listQuery.label"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="10">
                <el-button
                  v-for="item in searchBtn"
                  :key="item.label"
                  :icon="item.icon"
                  :type="item.type"
                  :disabled="item.disabled"
                  @click="item.handle()"
                >
                  {{ item.label }}
                </el-button>
              </el-col>
            </el-form>
          </el-col>
        </el-row>
      </div>
    </template>
    <template v-slot:table-main>
      <div class="depForm" ref="depForm">
        <el-form
          :model="depForm"
          ref="depRuleForm"
          label-width="auto"
          class="demo-ruleForm"
        >
          <div class="top">
            <el-form-item label="上级科室" prop="parentName">
              <template>
                <treeselect
                  style="width: 100%"
                  :disabled="showKeShi"
                  :options="treeSelectData"
                  :load-options="loadOptions"
                  :normalizer="normalizer"
                  clearable
                  placeholder="请选择科室名称"
                  v-model="depForm.parentId"
                >
                </treeselect>
              </template>
            </el-form-item>
            <el-form-item
              v-for="item in ItemList"
              :key="item.prop"
              :label="item.label"
              :prop="item.prop"
            >
              <el-input
                v-if="item.type === 'Input'"
                v-model="depForm[item.prop]"
                :disabled="formEdit"
                :placeholder="item.placeholder"
              />
              <el-select
                v-if="item.type === 'Select'"
                v-model="depForm[item.prop]"
                :disabled="formEdit"
                :placeholder="item.placeholder"
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="op in item.options"
                  :key="op.value"
                  :label="op.label"
                  :value="op.value"
                />
              </el-select>
              <el-select
                v-if="item.type === 'entryCodeType'"
                v-model="depForm[item.prop]"
                :disabled="formEdit"
                :placeholder="item.placeholder"
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="op in item.options"
                  :key="op.entryCode"
                  :label="op.entryValue"
                  :value="op.entryCode"
                />
              </el-select>
              <el-select
                v-if="item.type === 'basicIdType'"
                v-model="depForm[item.prop]"
                :disabled="formEdit"
                :placeholder="item.placeholder"
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="op in item.options"
                  :key="op.entryCode"
                  :label="op.entryValue"
                  :value="op.entryCode"
                />
              </el-select>
              <el-select
                v-if="item.type === 'administerSelect'"
                v-model="depForm[item.prop]"
                :disabled="item.disabled"
                :placeholder="item.placeholder"
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="op in item.options"
                  :key="op.value"
                  :value="op.value"
                  :label="op.label"
                />
              </el-select>
              <el-select
                v-if="item.type === 'directorSelect'"
                v-model="depForm[item.prop]"
                :disabled="item.disabled"
                :placeholder="item.placeholder"
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="op in doctorOptions"
                  :key="op.entryCode"
                  :value="op.hisMedicalStaffId"
                  :label="op.name"
                />
              </el-select>

              <el-select
                v-if="item.type === 'deputyDirectorSelect'"
                v-model="depForm[item.prop]"
                :disabled="item.disabled"
                :placeholder="item.placeholder"
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="op in doctorOptions"
                  :key="op.entryCode"
                  :value="op.hisMedicalStaffId"
                  :label="op.name"
                />
              </el-select>

              <el-radio-group
                v-if="item.type === 'Radio'"
                v-model="depForm[item.prop]"
                :disabled="formEdit"
              >
                <el-radio :label="1">启用</el-radio>
                <el-radio :label="0">禁用</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="挂号类别" prop="basicidDept">
              <el-select
                v-model="depForm.basicidDept"
                placeholder="挂号类别"
                style="width: 100%"
                :disabled="registerStatus"
                clearable
              >
                <el-option
                  v-for="(item, index) in regTypeOptions"
                  :key="index"
                  :label="item.entryValue"
                  :value="item.basicId"
                ></el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="bottom">
            <el-form-item>
              <el-button
                :disabled="formEdit"
                type="primary"
                @click="formStatus === 'create' ? create() : update()"
                >确定</el-button
              >
              <el-button :disabled="formEdit" @click="cancel">取消</el-button>
            </el-form-item>
          </div>
        </el-form>
      </div>
    </template>
  </departmentBase>
</template>

<script>
import departmentBase from "@/components/Layout/departmentBase.vue"
import SearchTrees from "@/components/Trees/SearchTrees.vue"
import searchMain from "@/components/CommonForm/form-item/DepartmentForm.vue"
import { addressList, dataProps } from "@/simdata/healthData.js"
import { validatenull, validatenotnull } from "@/utils/validate.js"
import {
  medicalStaffList,
  getLazyTreeDept,
  getChildNodeLazy,
  getById,
  LazyNodeTree,
  addDept,
  editDept,
  deleteDept,
  getLazyOrgTree,
  getOrganizationLazy,
  getCountHasChildren,
  getRegisterType
} from "@/api/setup/department.js"
import { LazyTree } from "@/api/setup/standard-department.js"
import { Treeselect } from "@riophae/vue-treeselect"
// import the styles
import "@riophae/vue-treeselect/dist/vue-treeselect.css"
import { entryCodeType, basicIdType } from "@/simdata/healthData.js"
import success from "@/utils/operation-message.js"
const defaultDic = {
  basicidDept: "", // 挂号类别
  hisDeptId: "", //
  code: "",
  name: "",
  abbreviation: "",
  parentId: null,
  grade: "",
  property: "",
  type: "",
  administerType: null, // 管理类别
  director: "",
  deputyDirector: "",
  sysOrganizationId: "",
  status: 1,
  remark: ""
}
export default {
  components: {
    departmentBase,
    SearchTrees,
    searchMain,
    Treeselect
  },
  data() {
    return {
      // 配置表单按钮
      searchBtn: [
        {
          label: "搜索",
          icon: "el-icon-search",
          type: "primary",
          disabled: false,
          handle: () => this.searchHandle()
        },
        {
          label: "下载科室",
          icon: "el-icon-download",
          type: "primary",
          disabled: false,
          handle: () => ""
          // this.initStatus()
        },
        {
          label: "新增",
          icon: "el-icon-circle-plus-outline",
          type: "primary",
          disabled: false,
          handle: () => this.handleCreate()
        }
      ],
      formData: {
        filterText: undefined, // 机构
        label: "" // 科室名
      },
      filterText: undefined,
      OrgOptions: [], // 机构下拉框数据
      treeSelectData: [], // 选择上级科室的下拉
      doctorOptions: [], // 选择科主任的下拉框
      listQuery: {
        //查询条件
        id: undefined,
        label: undefined,
        parentId: undefined,
        sysOrganizationId: undefined
      },
      deptId: [], // 下载节点
      orgdata: [], // 下载选中的节点
      // 控制上级科室的禁用
      showKeShi: true,
      isGetNode: true,
      // 控制表单的禁用
      formEdit: true,
      formStatus: "", // 控制是新增  还是修改
      // 配置是否默认加载假数据
      lazy: true,
      treeData: [
        {
          hisDicTypeId: "1001",
          name: "潜江市卫生健康委员会",
          parentId: "-1",
          hisDicTypeVOS: [
            {
              hisDicTypeId: "1001001",
              parentId: "1001",
              name: "潜江市龙湾镇卫生院",
              type: "org",
              hisDicTypeVOS: [
                {
                  hisDicTypeId: "04e3153e5c3d464eb739e19b97b3b0d2",
                  name: "医疗机构诊疗科目名录",
                  hisDicTypeVOS: [
                    {
                      hisDicTypeId: "6622648c9d534441bd3f3190ca1c36c1",
                      parentId: "04e3153e5c3d464eb739e19b97b3b0d2",
                      name: "公卫科"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      // 配置显示的label
      defaultProps: {
        id: "id",
        label: "label",
        children: "children",
        isLeaf: "isLeaf"
      },
      // 提交表单的字段
      depForm: Object.assign({}, defaultDic),
      formItemList: [
        {
          type: "Cascader",
          label: "",
          prop: "filterText",
          span: 8,
          options: [],
          // props: dataProps,
          // change: () => this.handleChange(),
          placeholder: "请选择机构"
        },
        {
          type: "Input",
          label: "",
          prop: "departmentName",
          span: 6,
          placeholder: "科室名称、科室编码"
        }
      ],
      // 查询医护人员列表
      doctorList: {
        sysOrgId: undefined, // 机构Id
        deptId: undefined // 科室id
      },
      registerStatus: true, // 挂号类别禁用
      parentIdPptions: [], // 上级科室下拉数据
      regTypeOptions: [], // 挂号类别下拉框
      // 配置显示的提交表单
      ItemList: [
        {
          type: "Input",
          label: "科室编码",
          prop: "code",
          disabled: true,
          placeholder: "请输入科室编码"
        },
        {
          type: "Input",
          label: "名称",
          prop: "name",
          disabled: true,
          placeholder: "请输入名称"
        },
        {
          type: "Input",
          label: "简称",
          prop: "abbreviation",
          disabled: true,
          placeholder: "请输入简称"
        },
        {
          type: "entryCodeType",
          label: "科室类别",
          prop: "type",
          options: entryCodeType,
          disabled: true,
          placeholder: "请选择科室类别"
        },
        {
          type: "basicIdType",
          label: "科室性质",
          prop: "property",
          options: basicIdType,
          disabled: true,
          placeholder: "请选择科室性质"
        },
        {
          type: "administerSelect",
          label: "管理类别",
          prop: "administerType",
          options: [
            { label: "全部", value: 1 },
            { label: "公卫", value: 2 },
            { label: "医疗", value: 3 }
          ],
          disabled: false,
          placeholder: "请选择管理类别"
        },
        {
          type: "directorSelect",
          label: "科主任",
          prop: "director",
          options: [],
          disabled: false,
          placeholder: "请选择科主任"
        },
        {
          type: "deputyDirectorSelect",
          label: "科副主任",
          prop: "deputyDirector",
          options: [],
          disabled: false,
          placeholder: "请选择科副主任"
        },
        {
          type: "Radio",
          label: "是否启用",
          prop: "status",
          options: [],
          disabled: true,
          placeholder: ""
        },
        {
          type: "Input",
          label: "描述",
          prop: "remark",
          disabled: true,
          placeholder: "请输入描述"
        }
        // {
        //   type: "Select",
        //   label: "挂号类别",
        //   prop: "basicidDept",
        //   options: [],
        //   disabled: true,
        //   placeholder: "请选择挂号类别"
        // }
      ],
      chosenSysOrgId: "", // 查询条件
      userInfo: JSON.parse(window.sessionStorage.getItem("userInfo"))
      // 模拟
      // userInfo: {
      //   sysOrganizationId: "1001005" // 机构id
      // }
    }
  },
  created() {
    this.getOrgList()
  },
  methods: {
    // 机构树查询
    async getOrgList() {
      let sysOrganizationId = this.userInfo.sysOrganizationId
      const res = await getLazyOrgTree(sysOrganizationId)
      console.log(res)
      if (res.code === "1000") {
        this.OrgOptions = res.data
      }
    },
    async chooseAnOrgan(node) {
      this.chosenSysOrgId = node.id
      let params = {
        sysOrganizationId: node.id
      }
      const res = await getOrganizationLazy(params)
      if (res.code === "1000") {
        this.treeData = res.data
      }
    },
    async inputAnOrgan(value) {
      if (!value) {
        this.chosenSysOrgId = this.userInfo.sysOrganizationId
        let params = {
          sysOrganizationId: this.userInfo.sysOrganizationId
        }
        const res = await getOrganizationLazy(params)
        if (res.code === "1000") {
          this.treeData = res.data
        }
      }
    },
    // 科室树查询
    async getMenuList() {
      // this.listQuery.sysOrganizationId = this.chosenSysOrgId
      if (validatenull(this.listQuery.label)) {
        this.listQuery.sysOrganizationId = this.userInfo.sysOrganizationId
        this.listQuery.parentId = ""
        const res = await getOrganizationLazy(this.listQuery)
        // console.log(res)
        if (res.code === "1000") {
          this.treeData = res.data
        }
      } else {
        this.listQuery.sysOrganizationId = this.chosenSysOrgId
        this.listQuery.parentId = ""
        const resA = await getLazyTreeDept(this.listQuery)
        if (resA.code === "1000") {
          this.treeData = resA.data
        }
      }
    },
    // 获取节点数据
    async lazyLoad(node, resolve) {
      console.log(node)
      if (node.level === 0) {
        if (validatenull(this.listQuery.label)) {
          this.listQuery.sysOrganizationId = this.userInfo.sysOrganizationId
        } else {
          this.listQuery.parentId = ""
        }
        // 有权限了再请求下面接口
        // const res = await getLazyOrgTree(this.listQuery)
        const res = await getOrganizationLazy(this.listQuery)
        // console.log(res)
        if (res.code === "1000") {
          this.treeData = res.data
          return resolve(this.treeData)
        }
      } else {
        if (node.data.type === "org") {
          //节点为机构
          if (node.data.hasChildrenId) {
            //有下级机构就查询下级机构
            const resA = await LazyNodeTree(node.data.id)
            // console.log(resA)
            if (resA.code === "1000") {
              resolve(resA.data)
            }
          } else {
            //没有下级机构就查询它的科室
            this.listQuery.parentId = "-1"
            this.listQuery.sysOrganizationId = node.data.id
            const resB = await getLazyTreeDept(this.listQuery)
            if (resB.code === "1000") {
              resolve(resB.data)
            }
          }
        } else {
          //节点为科室就查询该节点下级科室
          const resC = await getChildNodeLazy(node.data.id)
          // console.log(resC)
          if (resC.code === "1000") {
            resolve(resC.data)
          }
        }
      }
    },
    // 查询挂号类别下拉数据
    async getRegisterType() {
      const res = await getRegisterType(this.userInfo.sysOrganizationId)
      if (res.code === "1000") {
        this.regTypeOptions = res.data
      }
    },
    async filterNode(value, data) {
      //树结构过滤
      let params = {
        parentId: "",
        sysOrganizationId: value
      }
      const res = await getOrganizationLazy(params)
      if (res) {
        this.treeData = res.data
      }
    },
    // 监听左侧树的点击数据
    async handleNodeClickTree(data, node) {
      // console.log(data)
      //获取节点数据(可编辑修改)
      if (this.isGetNode) {
        if (data.type === "org") {
          this.cancel()
          return
        } else {
          this.formStatus = "update"
          this.formEdit = false
          this.resetForm()
          //查询医护人员
          this.doctorList.sysOrgId = data.sysOrganizationId
          this.doctorList.deptId = data.id
          // 修改科室，先使用科室主键与医护人员表HIS_DEPT_ID（行政科室编码）字段关联查询医护人员，关联没有结果就获取该机构所有医护人员
          const res = await medicalStaffList(this.doctorList)
          // console.log(res)
          if (res && res.code === "1000") {
            if (res.data.length > 0) {
              this.doctorOptions = res.data
            } else {
              this.doctorList.deptId = ""
              const result = await medicalStaffList(this.doctorList)
              if (result.code === "1000") {
                this.doctorOptions = result.data
              }
            }
          }
          if (data.parentId === "-1") {
            //查询上级科室
            let params = {
              id: data.id
            }
            const resA = await getLazyTreeDept(params)
            if (resA.code === "1000") {
              let Data = resA.data
              this.treeSelectData = []
              this.treeSelectData.push({
                id: "-1",
                label: "根节点",
                children: Data
              })
            }
            const resB = await getById(data.id)
            if (resB.code === "1000") {
              // 科室性质与科室类别不为null时转为字符串，result中返回number，下拉框的value为string
              let result = resB.data
              result.property =
                result.property != null ? "" + result.property : null
              result.type = result.type != null ? "" + result.type : null
              if (result.type == 5) {
                this.searchBtn[1].disabled = true // 下载禁用
                this.searchBtn[2].disabled = true // 新增禁用
              } else {
                this.searchBtn[1].disabled = false
                this.searchBtn[2].disabled = false
              }
              if (result.type == 3) {
                this.registerStatus = false // 挂号类别禁用
              } else {
                this.registerStatus = true
              }
              this.depForm = result
              this.depForm.parentId = "-1"
              // 科室基础字典表主键不为null，表示从标准科室复制而来，不可修改
              if (result.hisDeptDicId) {
                this.formEdit = true
              }
            }
          } else {
            //查询上级科室
            let params = {
              id: data.parentId
            }
            const resC = await getLazyTreeDept(params)
            if (resC.code === "1000") {
              this.treeSelectData = resC.data
            }
            const resD = await getById(data.id)
            if (resD.code === "1000") {
              //获取节点数据方法
              let result = resD.data
              // 科室性质与科室类别不为null时转为字符串，result中返回number，下拉框的value为string
              result.property =
                result.property != null ? "" + result.property : null
              result.type = result.type != null ? "" + result.type : null
              if (result.type == 5) {
                this.searchBtn[1].disabled = true // 下载禁用
                this.searchBtn[2].disabled = true // 新增禁用
              } else {
                this.searchBtn[1].disabled = false
                this.searchBtn[2].disabled = false
              }
              if (result.type == 3) {
                this.registerStatus = false
              } else {
                this.registerStatus = true
              }
              this.depForm = result
              // 科室基础字典表主键不为null，表示从标准科室复制而来，不可修改
              if (result.hisDeptDicId) {
                this.formEdit = true
              }
            }
          }
        }
      }
    },
    searchHandle() {
      this.getMenuList()
    },

    normalizer(node) {
      //去掉children=[]的children属性
      if (node.children && !node.children.length) {
        delete node.children
      }
    },
    // 下拉树的延迟加载
    async loadOptions({ action, parentNode, callback }) {
      // console.log(parentNode)
      // if (action === LOAD_CHILDREN_OPTIONS) {
      if (parentNode.type === "org") {
        if (!parentNode.isLeaf) {
          const res = await LazyNodeTree(parentNode.id)
          if (res.code === "1000") {
            parentNode.children = res.data
            callback()
          }
          return
        }
        if (parentNode.hasChildrenId) {
          //有下级机构就查询下级机构
          const resA = await LazyNodeTree(parentNode.id)
          if (resA.code === "1000") {
            parentNode.children = resA.data
            callback()
          }
        } else {
          //没有下级机构就查询它的科室
          let params = {
            parentId: "-1",
            sysOrganizationId: parentNode.id
          }
          const resB = await getLazyTreeDept(params)
          if (resB.code === "1000") {
            parentNode.children = resB.data
            callback()
          }
        }
      } else {
        // 有下级   查询下级机构
        const resC = await getChildNodeLazy(parentNode.id)
        if (resC.code === "1000") {
          parentNode.children = resC.data
          callback()
        }
      }
      // }
    },
    // 点击新增按钮
    async handleCreate() {
      let orgDeptdata = this.$refs.SearchTrees.$refs.treeList.getCurrentNode()
      if (
        orgDeptdata === null ||
        (orgDeptdata.type == "org" && orgDeptdata.hasChildrenId != null)
      ) {
        this.$message({
          message: "请选中一个最小机构或科室",
          type: "warning"
        })
        return
      } else {
        this.resetForm()
        this.formEdit = false
        this.formStatus = "create"
        this.$nextTick(() => {
          this.$refs.depRuleForm.clearValidate()
        })
        if (orgDeptdata.type === "org") {
          //如果选择的是机构就查询机构下面的科室
          let params = {
            parentId: "-1",
            sysOrganizationId: orgDeptdata.id
          }
          const res = await getLazyTreeDept(params)
          if (res.code === "1000") {
            let data = res.data
            this.treeSelectData = []
            this.treeSelectData.push({
              id: "-1",
              label: "根节点",
              children: data
            })
            // const options = this.ItemList.filter(
            //   item => item.prop == "parentId"
            // )
            // if (options.length > 0) {
            //   options[0].options = this.parentIdPptions
            // }
            this.depForm.parentId = "-1"
            this.depForm.sysOrganizationId = orgDeptdata.id
          }
        } else {
          // 如果是科室
          let params = {
            id: orgDeptdata.id
          }
          const resA = await getLazyTreeDept(params)
          if (resA.code === "1000") {
            // console.log(resA)
            this.treeSelectData = resA.data
            // const optionsA = this.ItemList.filter(
            //   item => item.prop == "parentId"
            // )
            // if (optionsA.length > 0) {
            //   optionsA[0].options = resA.data
            // }
            this.depForm.parentId = orgDeptdata.id
            this.depForm.sysOrganizationId = orgDeptdata.sysOrganizationId
          }
        }
        if (orgDeptdata.type === "org") {
          this.doctorList.sysOrgId = orgDeptdata.id
        } else {
          this.doctorList.sysOrgId = orgDeptdata.sysOrganizationId
          this.doctorList.deptId = ""
        }
        // 获取科主任
        const director = await medicalStaffList(this.doctorList)
        // console.log(director)
        if (director.code === "1000") {
          let directorOptions = this.ItemList.filter(
            item => item.prop == "director"
          )
          if (directorOptions.length > 0) {
            directorOptions[0].options = director.data
          }
          let deputyDirectorOptions = this.ItemList.filter(
            item => item.prop == "deputyDirector"
          )
          if (deputyDirectorOptions.length > 0) {
            deputyDirectorOptions[0].options = director.data
          }
        }
      }
    },

    // 修改
    async update() {
      this.formEdit = true
      this.depForm.sysOrganizationId = this.userInfo.sysOrganizationId
      console.log(this.depForm)
      const res = await editDept(this.depForm)
      if (res.code) {
        this.formEdit = false
        this.cancel()
        this.listQuery.parentId = ""
        this.listQuery.sysOrganizationId = this.userInfo.sysOrganizationId
        this.getMenuList()
        success()
      }
    },

    // 删除
    async deleteHandle(node, data) {
      this.isGetNode = false
      const res = await getCountHasChildren(data.id)
      if (res.code === "1000") {
        let count = res.data
        if (count > 0) {
          this.$message({
            message: "该科室有下级科室，请先删除下级",
            type: "warning",
            duration: 2000
          })
          return
        } else {
          this.$confirm("确认删除当前记录吗?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
            closeOnClickModal: false
          })
            .then(() => {
              deleteDept(data.id).then(res => {
                if (res.code === "1000") {
                  this.$refs.SearchTrees.$refs.treeList.remove(node, data)
                  this.cancel()
                  // this.getMenuList()
                  this.isGetNode = true
                  success()
                }
              })
            })
            .catch(error => {
              console.log(error)
            })
        }
      }
    },

    // 下载
    initStatus() {
      //获取选中节点
      this.orgdata = this.$refs.SearchTrees.$refs.treeList.getCurrentNode()
      if (validatenotnull(this.orgdata)) {
        if (this.orgdata.type === "org") {
          this.deptId = []
          const res = this.getDeptList
        }
      }
    },
    // 查询标准科室树
    async getDeptList() {
      this.orgdata = this.$refs.SearchTrees.$refs.treeList.getCurrentNode()
      const res = await LazyTree({
        parentId: "-1",
        sysOrganizationId: organId
      })
      if (res.code === "1000") {
        let resultTree = res.data
        resultTree.filter(item => {
          if (item.isCopy) {
            this.deptId.push(item.id)
          }
        })
      }
    },

    // 取消按钮
    cancel() {
      this.resetForm()
      this.searchBtn[1].disabled = false
      this.searchBtn[2].disabled = false
      this.formEdit = true
      this.formStatus = ""
    },
    // 点击提交
    async create() {
      // console.log(this.depForm)
      this.formEdit = true

      const res = await addDept(this.depForm)
      // console.log(res)
      if (res.code === "1000") {
        this.formEdit = false
        this.cancel()
        this.listQuery.sysOrganizationId = this.userInfo.sysOrganizationId
        this.getMenuList()
        success()
      }
    },
    // 重置
    resetForm() {
      this.depForm = Object.assign({}, defaultDic)
    }
  }
}
</script>
<style lang="scss" scoped>
.main-search {
  /deep/ .vue-treeselect__control {
    height: 28px !important;
    line-height: 28px !important;
  }
  /deep/ .vue-treeselect__single-value {
    line-height: 28px !important;
  }
  .el-row {
    display: flex;
    flex-wrap: wrap;
  }
  .item {
    width: 100%;
    display: flex;
    /deep/.el-form-item__content {
      flex: 1;
    }
  }
}
/deep/ .table-item {
  height: 100%;
  margin-right: 0 !important;
}
.depForm {
  height: 100%;
  .el-form {
    width: 80%;
    height: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    .top {
      flex: 1;
      padding: 20px 0;
      overflow: hidden;
      overflow-y: auto;
      padding-right: 30px;
    }
    .bottom {
      .el-form-item {
        height: 80px;
        /deep/ .el-form-item__content {
          padding-top: 30px;
        }
      }
    }
  }
}
</style>
